Implement the bash tool
title: "Build Your Own Redis, Git & SQLite From Scratch" source: "https://app.codecrafters.io/courses/claude-code/stages/oq5" author: published: created: 2026-05-31 description: "Advanced programming challenges for experienced engineers. Rebuild real production tools like Redis, Git, and SQLite from scratch in your IDE." tags: - "clippings"
Implement the bash tool #oq5
In-progress
Your Task¶
In-progress
Easy
In this stage, you'll add support for the Bash tool.
The Bash Tool¶
The Bash tool enables the LLM to run shell commands. It gives the model direct access to the command line to perform actions like deleting files, creating directories, or running scripts.
You'll need to advertise the Bash tool in your request and execute it when the model requests it.
Here is an example of the Bash tool's specification:
{
"type": "function",
"function": {
"name": "Bash",
"description": "Execute a shell command",
"parameters": {
"type": "object",
"required": ["command"],
"properties": {
"command": {
"type": "string",
"description": "The command to execute"
}
}
}
}
}
Executing the Bash Tool¶
When the model requests a Bash tool call:
- Parse the arguments to extract the
command - Execute the command using your language's shell execution capabilities (e.g.,
subprocess.run()in Python,child_process.exec()in Node.js) - Capture both stdout and stderr from the command
- Return the command output (or an error message if it failed) to the model as a tool message
For example, if the command is rm README_old.md, execute it and return the result (which will be empty if successful).
Tests¶
The tester will create three files:
app/main.js- Main project fileREADME.md- The current readme fileREADME_old.md- An old readme file
The tester will then execute your program like this:
$ ./your_program.sh -p "Delete the old readme file."
Deleted README_old.md
The tester will verify that:
README_old.mdhas been deleted (no longer exists)app/main.jsremains intact with its original contentsREADME.mdremains intact with its original contents- Your program exits with code
0
Notes¶
- You can choose any reasonable name for the Bash tool (e.g.,
Bash,bash,RunBashCommand,run_bash_command). - The result of the
Bashtool call should be sent back to the model as part of the agent loop. - Make sure to execute the command in the same directory as your program, not in a temporary or different working directory.
How to pass this stage¶
1
Write code to pass this stage
Head over to your editor / IDE and implement your solution.
If you want a quick look at what functions to use or how to structure your code, we recommend looking at Code Examples.
2
Submit code
To run tests, make changes to your code and run the submit command:
codecrafters submit # Visit https://codecrafters.io/cli to install
Test Runner:
Ready to run tests
Hints¶
Filter by Python
Write
Preview
Complete this stage to hit #8636
Ready to run tests
Show logs